package org.aom.litebean.module.base;

import java.io.Serializable;

import org.operamasks.faces.annotation.Action;
import org.operamasks.faces.annotation.Bind;
import org.operamasks.faces.component.html.impl.UIIFrame;
import org.operamasks.faces.component.layout.impl.UIWindow;

public abstract class BaseGridCrudBean<T, PK extends Serializable> extends
		SimpleListBean<T, PK> {

	protected Long selectedModuleId;

	@Bind(id = "OperationDialog", attribute = "binding")
	protected UIWindow OperationDialog;

	@Bind(id = "OperationFrame", attribute = "binding")
	protected UIIFrame OperationFrame;

	public static String SELECTED_MODULE_ID = "selectedModuleId";
	public static String ACTION_NAME = "action";

	protected abstract void initAdd();

	protected abstract void processToSearch();

	protected abstract void processToEdit();

	@Action(id = "del", event = "onclick")
	protected abstract void delete();;

	protected void processToAdd() {
		initAdd();
	};

	@SuppressWarnings("unchecked")
	protected T getSelectEntity() {
		return (T) getDataGrid().getSelectedValues()[0];
	}
	/**
	 * 给予操作UIDataGrid进行各种操作完刷新数据源并重置其选择器窗台功能
	 */
	protected void resetGrid(){
		getDataGrid().setSelections(new int[] { -1 });
		getDataGrid().reload();
	} 

	/*
	 * 绑定页面refesh按钮
	 */
	@Action
	public void refesh() {
		resetGrid();
		OperationDialog.close();
	}
}
